package Comprehensive_04;

public class Test7 implements Runnable {
    private int num;

    public Test7(int num) {
        this.num = num;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public static void main(String[] args) throws InterruptedException {
        Test7 test = new Test7(0);
        /*new Thread(()->{
            for (int i = 0; i < 1000; i++) {
                test.setNum(test.getNum() + 1);
            }
        }).start();

        new Thread(()->{
            for (int i = 0; i < 1000; i++) {
                test.setNum(test.getNum() + 1);
            }
        }).start();*/

        new Thread(test).start();
        new Thread(test).start();

        Thread.sleep(500);
        System.out.println(test.getNum());
    }

    @Override
    public void run() {
        for (int i = 0; i < 1000; i++) {
            setNum(num + 1);
        }
    }
}
